/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openbookformat.project;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
 *
 * @author matamh0a
 */
public class HeadingPointer {
    public static final String PROP_LEVEL = "level";
    public static final String PROP_HEADING = "heading";

    protected Chapter chapter;
    protected int offset;
    protected int level;
    protected String heading;
    
    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
    
    public HeadingPointer(Chapter chapter, int offset, int level, String heading) {
        this.chapter = chapter;
        this.offset = offset;
        this.level = level;
        this.heading = heading;
    }

    public Chapter getChapter() {
        return chapter;
    }

    public void setChapter(Chapter chapter) {
        this.chapter = chapter;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }
    
        /**
     * Get the value of heading
     *
     * @return the value of heading
     */
    public String getHeading() {
        return heading;
    }

    /**
     * Set the value of heading
     *
     * @param heading new value of heading
     */
    public void setHeading(String heading) {
        String oldHeading = this.heading;
        this.heading = heading;
        propertyChangeSupport.firePropertyChange(PROP_HEADING, oldHeading, heading);
    }
    
    
    /**
     * Get the value of level
     *
     * @return the value of level
     */
    public int getLevel() {
        return level;
    }

    /**
     * Set the value of level
     *
     * @param level new value of level
     */
    public void setLevel(int level) {
        int oldLevel = this.level;
        this.level = level;
        propertyChangeSupport.firePropertyChange(PROP_LEVEL, oldLevel, level);
    }


    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final HeadingPointer other = (HeadingPointer) obj;
        if (this.chapter != other.chapter && (this.chapter == null || !this.chapter.equals(other.chapter))) {
            return false;
        }
        if (this.offset != other.offset) {
            return false;
        }
        if (this.level != other.level) {
            return false;
        }
        if ((this.heading == null) ? (other.heading != null) : !this.heading.equals(other.heading)) {
            return false;
        }
        return true;
    }
    
    @Override
    public String toString() {
        return "HeadingPointer{" + "chapter=" + chapter + ", offset=" + offset + ", level=" + level + ", heading=" + heading + '}';
    }
    
        /**
     * Add PropertyChangeListener.
     *
     * @param listener
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    /**
     * Remove PropertyChangeListener.
     *
     * @param listener
     */
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }

}
